<?php

class Reale_Model_DbTable_Agent extends Zend_Db_Table_Abstract
{
    /**
     * @var string Name of the database table
     */
    protected $_name = 'agent';
    
    public function delete($agent_reg_id){
        $sql = 'SET @agentRegId=?;
DELETE FROM `user_role` WHERE `user_id`=@agentRegId;
DELETE FROM `auth_user` WHERE `user_id`=@agentRegId;
DELETE `agent_address`,`agent_network`,`agent_nominee` ,`agent_register`
FROM
    `agent_address`
    INNER JOIN `agent` 
        ON (`agent_address`.`agent_id` = `agent`.`agent_id`)
    INNER JOIN `agent_network` 
        ON (`agent_network`.`agent_id` = `agent`.`agent_id`)
    INNER JOIN `agent_nominee` 
        ON (`agent_nominee`.`agent_id` = `agent`.`agent_id`)
    INNER JOIN `agent_register` 
        ON (`agent_register`.`agent_id` = `agent`.`agent_id`)
WHERE `agent`.agent_reg_id = @agentRegId;
DELETE FROM `agent` WHERE `agent_reg_id`=@agentRegId';
        $stmt = $this->getAdapter()->query($sql,$agent_reg_id);
        return $stmt->rowCount();
    }
}
